#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,l,w;
struct CAR{
	int d,v,a,ks,js;
	bool is;
}c[100210];
int p[100210];
bool cmp(CAR x,CAR y){
	return x.d<y.d;
}
bool dmp(CAR x,CAR y){
	if(!(x.is&&y.is))return x.is>y.is;
	return x.js<y.js;
}
bool emp(CAR x,CAR y){
	return x.a<y.a;
}
inline void A(){
	int ans=0;
	for(int i=0;i<n;i++){
		if(c[i].d<=p[m-1]&&c[i].v>w)ans++;
	}
	cout<<ans<<" ";
	if(ans)cout<<m-1;
	else cout<<m;
	cout<<'\n';
}
inline void B(){
	int ans=0;
	for(int i=0;i<n;i++){
		if(c[i].d<=p[m-1]){
			if(c[i].v*c[i].v+2*c[i].a*(p[m-1]-c[i].d)>w*w)ans++;
		}
	}
	cout<<ans<<" ";
	if(ans)cout<<m-1;
	else cout<<m;
	cout<<'\n';
}
inline void C(){
	int ans=0;
	int ii=0,jj=0;
	sort(c,c+n,cmp);
	for(;ii<m;ii++)
		for(;c[jj].d<=p[ii]&&jj<n;jj++){
			if(c[jj].v*c[jj].v+2*c[jj].a*(p[ii]-c[jj].d)>w*w){
				ans++;
				c[jj].is=1;
				c[jj].ks=c[jj].d;
				c[jj].js=c[jj].d+ceil((w*w-c[jj].v*c[jj].v)*1.0/2/c[jj].a);
			}
			else c[jj].is=0;
		}
	cout<<ans<<" ";
	sort(c,c+n,dmp);
	int i=0,j=0,kk=0;
	for(;i<n&&c[i].is;){
		for(;p[j]<c[i].js&&j<m;j++);
		j--;
		kk++;
		while(c[i].ks<=p[j]&&i<n)
			i++;
	}
	if(ans)cout<<m-kk;
	else cout<<m;
	cout<<'\n';
}
signed main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		cin>>n>>m>>l>>w;
		bool isA=1,isB=1,isC=1;
		for(int i=0;i<n;i++){
			cin>>c[i].d>>c[i].v>>c[i].a;
			if(c[i].a!=0)isA=0;
			if(c[i].a<=0)isB=0;
			if(c[i].a>=0)isC=0;
		}
		for(int i=0;i<m;i++)
			cin>>p[i];
		if(isA){
			A();
			continue;
		}
		if(isB){
			B();
			continue;
		}
		if(isC){
			C();
			continue;
		}
		int ans=0,bns=0;
		for(int i=0;i<n;i++){
			if(c[i].a==0){
				c[i].is=1;
				if(c[i].d<=p[m-1]&&c[i].v>w)ans++;
				else c[i].is=0;
			}
			if(c[i].a>0){
				if(c[i].d<=p[m-1]){
					c[i].is=1;
					if(c[i].v*c[i].v+2*c[i].a*(p[m-1]-c[i].d)>w*w)ans++;
					else c[i].is=0;
				}
			}
			if(c[i].a<0){
				bns++;
				for(int j=0;j<m;j++){
					if(p[j]>=c[i].d){
						if(c[i].v*c[i].v+2*c[i].a*(p[j]-c[i].d)>w*w){
							ans++;
							c[i].is=1;
							c[i].ks=c[i].d;
							c[i].js=c[i].d+ceil((w*w-c[i].v*c[i].v)*1.0/2/c[i].a);
						}
						else c[i].is=0;
						break;
					}
			 	}
			}
		}
		cout<<ans<<" ";
		sort(c,c+n,emp);
		sort(c,c+bns,dmp);
		int i=0,j=0,kk=0,flg=1;
		for(;i<bns&&c[i].is;){
			for(;p[j]<c[i].js&&j<m;j++);
			j--;
			kk++;
			while(c[i].ks<=p[j]&&i<bns)
				i++;
		}
		for(int ii=bns;ii<n;ii++){
			if(c[ii].d>p[j]&&c[ii].is)flg=0;
		}
		if(ans)cout<<m-kk-1+flg;
		else cout<<m;
		cout<<'\n';
	}        
	return 0;    
}